package com.lqq.designPattern.behavioral_pattern.iterator;

import java.util.ArrayList;
import java.util.List;

//具体迭代器
public class StudentIteratorImpl implements StudentIterator{
    private List<Student> list = new ArrayList<>();
    private int position = 0;//记录遍历的当前位置

    public StudentIteratorImpl(List<Student> list) {
        this.list = list;
    }

    @Override
    public boolean hasNext() {
        return position < list.size();
    }

    @Override
    public Student next() {
        Student currentStudent = list.get(position);
        position++;
        return currentStudent;
    }
}
